package org.idea.spring.ioc;

import org.idea.spring.ioc.bean.User;
import org.idea.spring.ioc.bean.UserFactoryBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.Date;

/**
 * @Author idea
 * @Date created in 10:44 下午 2020/5/12
 */
public class FactoryBeanDemo {

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.register(FactoryBeanDemo.class);
        annotationConfigApplicationContext.refresh();
        //可以是从factoryBean中获取
        User user = (User) annotationConfigApplicationContext.getBean("userFactoryBean");
        System.out.println(user.toString());

    }

    @Bean
    private UserFactoryBean userFactoryBean() {
        return new UserFactoryBean(12);
    }


}
